package org.canaan.http.urlpair.resolver.impl;


import org.canaan.http.urlpair.core.Utils;
import org.canaan.http.urlpair.resolver.UrlPairResolver;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * 基本类型解析器
 * @author Canaan
 * @date 2017/6/29 0029
 */
public class BaseTypeResolver implements UrlPairResolver {

    @Override
    public boolean resolvable(Object o) {

        if (o == null) {
            return true;
        }
        if (Integer.class.isInstance(o)) {
            return true;
        }else if(BigInteger.class.isInstance(o)){
            return true;
        }else if(BigDecimal.class.isInstance(o)){
            return  true;
        } else if (String.class.isInstance(o)) {
            return true;
        } else if (Float.class.isInstance(o)) {
            return true;
        } else if (Double.class.isInstance(o)) {
            return true;
        } else if (Short.class.isInstance(o)) {
            return true;
        } else if (Long.class.isInstance(o)) {
            return true;
        } else if (Character.class.isInstance(o)) {
            return  true;
        } else if (Boolean.class.isInstance(o)) {
            return true;
        } else if (Byte.class.isInstance(o)) {
            return true;
        }
        return false;
    }

    @Override
    public String resolve(String key,Object value) {
        if (value == null) {
            return key+"=";
        }
        if (String.class.isInstance(value)) {
            return key+"="+ Utils.urlEncoder(value.toString());
        }
        return key+"="+value;
    }

}
